package com.authenticateCenter.factory;

import com.authenticateCenter.domain.dto.AuthorityDto;
import com.authenticateCenter.domain.entity.Authority;
import com.authenticateCenter.domain.vo.AuthorityVo;
import com.security.domain.authority.CommonAuthority;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author 大忽悠
 * @create 2022/10/8 22:25
 */
public class AuthorityFactory {
    public static AuthorityConverter AUTHORITY_CONVERT = Mappers.getMapper(AuthorityConverter.class);

    @Mapper
    public interface AuthorityConverter {
        List<AuthorityVo> toListAuthorityVo(List<Authority> authority);

        AuthorityVo toAuthorityVo(Authority authority);

        @Mapping(target = "id", ignore = true)
        Authority toAuthority(AuthorityDto authorityDto);

        @Mapping(target = "authority", source = "pattern")
        CommonAuthority toCommonAuthority(AuthorityVo authorityVo);

        @Mapping(target = "authority", source = "pattern")
        List<CommonAuthority> toListCommonAuthority(List<AuthorityVo> authorityVo);
    }
}
